//
//  UIGLESSettingViewController.m
//  TextureFilter
//
//  Created by 畑圭輔 on 10/03/07.
//  Copyright 2010 Keisuke Hata. All rights reserved.
//

#import "UIGLESSettingViewController.h"

extern NSString * const kImageKeyCharactor2;

@implementation UIGLESSettingViewController

@synthesize glView;

- (IBAction) show {
	
	ControlView *view = (ControlView *)self.view;
	
	if( !_isOpened )
	{	
		[view open];
		_isOpened = YES;
		
	}else {
		[view close];
		_isOpened = NO;
	}
	NSLog(@"show view");
}

// テクスチャフィルタの変更
- (IBAction) selectedTextureFilter {

	[glView stopAnimation];
	SimpleFilterSpirte *sprite = [glView.renderTargets objectForKey:kImageKeyCharactor2];
	sprite.filter = _textureFilter.selectedSegmentIndex;
	NSLog(@"selectedTextureFilter : %d" , _textureFilter.selectedSegmentIndex );
	[glView startAnimation];
}

// テクスチャラップの変更
- (IBAction) selectedTextureWrap {
	
	[glView stopAnimation];
	SimpleFilterSpirte *sprite = [glView.renderTargets objectForKey:kImageKeyCharactor2];
	sprite.wrap = _textureWrap.selectedSegmentIndex;
	NSLog(@"selectedTextureWrap : %d" , _textureWrap.selectedSegmentIndex );
	[glView startAnimation];
}

// UVラップの値の変更
- (IBAction) changedUVWrapValue {

	SimpleFilterSpirte *sprite = [glView.renderTargets objectForKey:kImageKeyCharactor2];
	float uv = _uvWrap.value;
	sprite.uv = uv;
	NSLog(@"changedUVWrapValue : %f" , uv);
	_uvWrapText.text = [NSString stringWithFormat:@"%.1f",uv];
}

// UVオフセットの値の変更
- (IBAction) changedUVOffset {
	
	SimpleFilterSpirte *sprite = [glView.renderTargets objectForKey:kImageKeyCharactor2];
	float offs = _uvOffset.value;
	sprite.offset = offs;
	NSLog(@"changedUVOffset : %f" , offs);
	_uvOffsetText.text = [NSString stringWithFormat:@"%.1f",offs];
}


/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
	
	_isOpened = NO;
	
	NSLog(@"viewLoad!!");
	CGRect frame = self.view.frame;
	frame.origin.y = self.view.frame.size.height - 40;
	[self.view setFrame:frame];
    [super viewDidLoad];
	
	_uvOffsetText.text = @"0.0";
	_uvWrapText.text   = @"1.0";
}

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}

- (void)dealloc {
    [super dealloc];
}


@end
